/********************************************
 *      
 * Created by zlj on 2024/9/19.
********************************************/
#include "stdint.h"
#include "stdio.h"
#define DATA_POINTS 10

// 线性回归预测
void linear_regression_predict(uint16_t *data, size_t data_size) {
    // 数据点数不足时返回
    if (data_size < 2) return;

    float x_sum = 0, y_sum = 0, xy_sum = 0, x2_sum = 0;
    for (size_t i = 0; i < data_size; i++) {
        x_sum += i;
        y_sum += data[i];
        xy_sum += i * data[i];
        x2_sum += i * i;
    }

    float slope = (data_size * xy_sum - x_sum * y_sum) / (data_size * x2_sum - x_sum * x_sum);
    float intercept = (y_sum - slope * x_sum) / data_size;

    printf("Slope: %f, Intercept: %f\n", slope, intercept);

    // 预测未来值
    float future_x = data_size;
    float future_y = slope * future_x + intercept;
    printf("Predicted future value: %f\n", future_y);
}